# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=libmetalink
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat")
checkdepends=("${MINGW_PACKAGE_PREFIX}-cunit")
pkgver=0.1.3
pkgrel=3
pkgdesc="Metalink library (mingw-w64)"
arch=('any')
url='https://launchpad.net/libmetalink'
license=('MIT')
source=("https://launchpad.net/${_realname}/trunk/${_realname}-${pkgver}/+download/${_realname}-${pkgver}.tar.xz")
sha256sums=('86312620c5b64c694b91f9cc355eabbd358fa92195b3e99517504076bf9fe33a')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd ${srcdir}/build-${CARCH}
  make check
}

package() {
  cd ${srcdir}/build-${CARCH}
  make install DESTDIR="${pkgdir}"
  
  local PREFIX_DEPS=$(cygpath -am ${MINGW_PREFIX})
  pushd "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig" > /dev/null
  sed -s "s|${PREFIX_DEPS}|${MINGW_PREFIX}|g" -i ./libmetalink.pc
  popd > /dev/null
}
